Option Strict Off
Option Explicit On
Friend Class costosParam
	Inherits System.Windows.Forms.Form
	
	Private Sub costosParam_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim i, j As Integer
		Dim aux As String
		Dim numfil, cont As Integer
		Dim linea As String
		
		
		band = band
		cmbAnali.SelectedIndex = 0 'fisicoquimico
		'Por defecto no es basico
		opt_no.Checked = True
		'por defecto bacterias
		If band = 2 Then cmb_ensayo.SelectedIndex = 0
		'si escoge microbiologico
		If cmbAnali.SelectedIndex = 1 Then cmb_ensayo.SelectedIndex = 0
		numfil = FreeFile 'numero de archivo libre
		'abrir el archivo para leer
		FileOpen(numfil, "D:\PROYECTO_CASA\software\casa\v1.3\titulo_nuevoParam.txt", OpenMode.Input)
		i = 0 : cont = 0
		'Close #numfil
		Do While Not EOF(numfil)
			'Lee la linea
			linea = LineInput(numfil)
			
			If i = 0 Then
				lbl1(i).Text = linea
				txt(i).Visible = True
			Else
				Select Case band
					Case Is = 1 'FISICO
						If linea <> "ENSAYO MICROBIOLOGICO" Then
							If linea = "ENSAYO BASICO" Then
								Call tipoEnsayo(i - 1, linea, 0) 'i = i - 1
							Else
								Call cargar(i, linea, 0, 500)
							End If
						End If
						lbl3.Visible = False : cmbAnali.Visible = False
					Case Is = 2 'MICRO
						If linea = "ENSAYO BASICO" Then
							Call tipoEnsayo(i - 1, linea, 0) 'i = i - 1
						ElseIf linea = "ENSAYO MICROBIOLOGICO" Then 
							Call tipoEnsayo(i, linea, 1) : i = i - 1
						Else
							Call cargar(i, linea, 0, 800)
						End If
						' costosParam.Height = 6800 '6540
						
						lbl3.Visible = False : cmbAnali.Visible = False
					Case Is = 3 'MOSTRAR LOS DATOS
						
						lbl3.Visible = True : cmbAnali.Visible = True
						If cmbAnali.SelectedIndex = 0 Then
							cmb_ensayo.Enabled = False
						End If
						If linea = "ENSAYO BASICO" Then
							Call tipoEnsayo(i - 1, linea, 0) 'i = i - 1
						ElseIf linea = "ENSAYO MICROBIOLOGICO" Then 
							Call tipoEnsayo(i, linea, 1)
							i = i - 1
						Else
							Call cargar(i, linea, 0, 800)
						End If
				End Select
			End If
			If band = 1 And linea <> "ENSAYO MICROBIOLOGICO" And linea <> "ENSAYO BASICO" Then
				i = i + 1
			ElseIf band = 2 And linea <> "ENSAYO BASICO" Then  'microbiologico
				i = i + 1
			ElseIf band = 3 And linea <> "ENSAYO BASICO" Then 
				i = i + 1
			End If
			
		Loop 
		Me.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(txt(0).Height) + VB6.PixelsToTwipsY(Me.Height)) '6540 '6800
	End Sub
	
	Sub cargar(ByRef i As Integer, ByRef texto As String, ByRef j As Short, ByRef sum As Integer)
		txt.Load(i)
		lbl1.Load(i)
		If j = 0 Then
			If i <> 5 Then sum = 0
			txt(i).Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(txt(i - 1).Top) + VB6.PixelsToTwipsY(txt(i - 1).Height) + sum) '300 '270
			lbl1(i).Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(lbl1(i - 1).Top) + VB6.PixelsToTwipsY(txt(i - 1).Height) + sum) '300 '270
		Else
			txt(i).Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(txt(i).Top) + 300) '270
			lbl1(i).Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(lbl2(j).Top) + 300) '270
		End If
		lbl1(i).Text = texto
		lbl1(i).Visible = True
		txt(i).Visible = True
	End Sub
	Sub tipoEnsayo(ByRef i As Integer, ByRef texto As Object, ByRef j As Integer)
		If j = 1 Then lbl2.Load(j)
		'UPGRADE_WARNING: Couldn't resolve default property of object texto. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		lbl2(j).Text = texto
		If j = 0 Then
			lbl2(j).Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(lbl1(i).Top) + VB6.PixelsToTwipsY(txt(i).Height))
			opt_no.Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(lbl1(i).Top) + VB6.PixelsToTwipsY(txt(i).Height))
			opt_si.Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(lbl1(i).Top) + VB6.PixelsToTwipsY(txt(i).Height))
			opt_no.Visible = True : opt_si.Visible = True
		Else
			lbl2(j).Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(lbl2(j).Top) + 300)
			cmb_ensayo.Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(opt_si.Top) + 300) : cmb_ensayo.Visible = True
		End If
		lbl2(j).Visible = True
		
		
		
	End Sub
	'UPGRADE_WARNING: Event cmbAnali.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbAnali_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbAnali.SelectedIndexChanged
		
		If cmbAnali.SelectedIndex = 1 Then
			cmb_ensayo.Enabled = True : cmb_ensayo.Text = ""
		Else
			cmb_ensayo.Enabled = False : cmb_ensayo.Text = ""
		End If
		
	End Sub
	Private Sub cmdAdd_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAdd.Click
		Dim aux, aux1 As String
		Dim tam, i As Integer
		
		' GUARDAR ---
		tam = txt.Count
		'cmb_ensayo
		If txt(0).Text <> "" And txt(1).Text <> "" And txt(2).Text <> "" And txt(3).Text <> "" And txt(4).Text <> "" Then
			
			
			'basico
			If opt_si.Checked = True Then
				aux = "'" & txt(0).Text & "','" & txt(2).Text & "','" & txt(10).Text & "','" & txt(11).Text & "','" & txt(5).Text & "','" & txt(4).Text & "','B'"
			ElseIf opt_no.Checked = True Then 
				aux = "'" & txt(0).Text & "','" & txt(2).Text & "','" & txt(10).Text & "','" & txt(11).Text & "','" & txt(5).Text & "','" & txt(4).Text & "','N'"
			Else ' por defecto si no escoge va ser basico
				aux = "'" & txt(0).Text & "','" & txt(2).Text & "','" & txt(10).Text & "','" & txt(11).Text & "','" & txt(5).Text & "','" & txt(4).Text & "','B'"
			End If
			'tipo analisis
			Select Case band
				Case Is = 1
					'aux = aux & ",'fi','','n',0"
					aux = aux & ",'fi','" & txt(6).Text & "','n',0"
					
				Case Is = 2
					
					If cmb_ensayo.SelectedIndex = 0 Then
						'aux = aux & ",'mi','','bacte',0"
						aux = aux & ",'mi','" & txt(6).Text & "','bacte',0"
					ElseIf cmb_ensayo.SelectedIndex = 1 Then 
						'aux = aux & ",'mi','','parasi',0"
						aux = aux & ",'mi','" & txt(6).Text & "','parasi',0"
					ElseIf cmb_ensayo.SelectedIndex = 2 Then 
						'aux = aux & ",'mi','','viral',0"
						aux = aux & ",'mi','" & txt(6).Text & "','viral',0"
					ElseIf cmb_ensayo.SelectedIndex = 3 Then 
						'aux = aux & ",'mi','','otros',0"
						aux = aux & ",'mi','" & txt(6).Text & "','otros',0"
					End If
					
				Case Is = 3
					If cmbAnali.SelectedIndex = 0 Then
						aux = aux & ",'fi','" & txt(6).Text & "','n',0"
					ElseIf cmbAnali.SelectedIndex = 1 Then 
						Select Case cmb_ensayo.SelectedIndex
							Case Is = 0
								'aux = aux & ",'mi','','bacte',0"
								aux = aux & ",'mi','" & txt(6).Text & "','bacte',0"
							Case Is = 1
								'aux = aux & ",'mi','','parasi',0"
								aux = aux & ",'mi','" & txt(6).Text & "','parasi',0"
							Case Is = 2
								'aux = aux & ",'mi','','viral',0"
								aux = aux & ",'mi','" & txt(6).Text & "','viral',0"
							Case Is = 3
								'aux = aux & ",'mi','','otros',0"
								aux = aux & ",'mi','" & txt(6).Text & "','otros',0"
						End Select
					End If
					
			End Select
			
			aux = "''," & aux & ",'" & txt(1).Text & "','" & txt(3).Text & "','" & txt(7).Text & "','" & txt(8).Text & "','" & txt(9).Text & "'"
			'-- INSERTAR PARAMETRO
			Call insertAdd("costos_quimicos1", aux)
			
			'fin obligatorios
		End If
	End Sub
	'Validar
	Private Sub txt_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txt.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		Dim Index As Short = txt.GetIndex(eventSender)
		
		Select Case Index
			Case Is = 0 'letras
				Call validarText(KeyAscii, 1)
			Case Is = 3 'numeros y .
				Call validarText(KeyAscii, 16)
			Case Is = 10, Is = 11 'numeros y ,
				Call validarText(KeyAscii, 17)
		End Select
		
		'
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
End Class